<?php

namespace App\Models\Entity\Asset\Video\Media;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class Vifile
 * @package App\Models\Entity\Asset\Video\Media
 * @version August 1, 2017, 4:32 pm UTC
 */
class Vifile extends Model
{
    use SoftDeletes;

    public $table = 'vifiles';

    protected $dates = ['deleted_at'];

    public $fillable = [
        'sp_id',
        'resolution_id',
        'vfileext_id',
        'title',
        'subtitle',
        'name',
        'alias_name',
        'path',
        'size',
        'md5',
        'duration',
        'href',
        'short_desc',
        'long_desc',
        'created_at',
        'updated_at',
        'type',
        'listorder',
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'sp_id'         => 'integer',
        'resolution_id' => 'integer',
        'vfileext_id'   => 'integer',
        'title'         => 'string',
        'subtitle'      => 'string',
        'name'          => 'string',
        'alias_name'    => 'string',
        'path'          => 'string',
        'size'          => 'decimal',
        'md5'           => 'string',
        'duration'      => 'string',
        'href'          => 'string',
        'short_desc'    => 'string',
        'long_desc'     => 'string',
        'type'          => 'tinyInteger',
        'listorder'     => 'integer',
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'sp_id'         => 'required|max:10',
        'resolution_id' => 'required|max:100',
        'vfileext_id'   => 'required|max:100',
        'title'         => 'max:100',
        'subtitle'      => 'max:100',
        'name'          => 'required|max:100',
        'path'          => 'required|max:100',
        'size'          => 'required',
        'md5'           => 'required',
        'duration'      => 'required',
        'href'          => 'required|max:200',
        'short_desc'    => 'required|max:100',
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function sp()
    {
        return $this->hasOne(\App\Models\Common\EntityData\Channel\Sp::class, 'id', 'sp_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function resolution()
    {
        return $this->hasOne(\App\Models\Common\Enumdata\Video\Resolution::class, 'id', 'resolution_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function vfileext()
    {
        return $this->hasOne(\App\Models\Common\Enumdata\File\Video\Vfileext::class, 'id', 'vfileext_id');
    }
}
